package com.ld.poetry.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ld.poetry.aop.LoginCheck;
import com.ld.poetry.config.PoetryResult;
import com.ld.poetry.entity.LoveHistory;
import com.ld.poetry.service.LoveHistoryService;
import com.ld.poetry.vo.BaseRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 家庭信息 前端控制器
 * </p>
 *
 * @author sara
 * @since 2023-01-03
 */
@RestController
@RequestMapping("/love")
public class LoveController {

    @Autowired
    private LoveHistoryService loveHistoryService;


    /**
     * 保存Love
     */
    @LoginCheck(1)
    @PostMapping("/saveLove")
    public PoetryResult saveLove(@Validated @RequestBody LoveHistory loveHistory) {
        loveHistoryService.save(loveHistory);
        return PoetryResult.success();
    }


    /**
     * 删除Love
     */
    @GetMapping("/deleteLove")
    @LoginCheck(1)
    public PoetryResult deleteLove(@RequestParam("id") Integer id) {
        loveHistoryService.removeById(id);
        return PoetryResult.success();
    }


    /**
     * 更新Love
     */
    @PostMapping("/updateLove")
    @LoginCheck(1)
    public PoetryResult updateLove(@Validated @RequestBody LoveHistory loveHistory) {
        loveHistoryService.updateById(loveHistory);
        return PoetryResult.success();
    }


    /**
     * 查询LoveList
     */
    @PostMapping("/listLove")
    public PoetryResult<Page> listLove(@RequestBody BaseRequestVO baseRequestVO) {
        loveHistoryService.lambdaQuery()
                .eq(baseRequestVO.getStatus() != null, LoveHistory::getStatus, baseRequestVO.getStatus())
                .orderByDesc(LoveHistory::getCreateTime).page(baseRequestVO);
        return PoetryResult.success(baseRequestVO);
    }

}
